package com.sgb.kjwl.viewmodel.self;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.OrderUploadEntity;
import com.sgb.kjwl.model.entity.user.OrderServiceEntity;
import com.sgb.kjwl.view.ui.activity.self.order.EditOrderActivity;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class EditOrderModel {
    private EditOrderActivity activity;

    public EditOrderModel(EditOrderActivity activity) {
        this.activity = activity;
    }

    public void getChangeList(String orderId) {
        DialogHelper.showProgressDialog(activity, null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getOrderAPI().getChangeList(orderId).enqueue(new Callback<BaseEntity<List<OrderServiceEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<OrderServiceEntity>>> call, Response<BaseEntity<List<OrderServiceEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) return;
                activity.showOrderList(response.body().getData());
            }

            @Override
            public void onFailure(Call<BaseEntity<List<OrderServiceEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }


    public void saveChangeList(List<OrderUploadEntity> data) {
        APIManager.getInstance().getOrderAPI().editOrder(data).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                if (response.body() == null || response.body().getState() == null) return;
                MToast.showToast(activity, response.body().getMsg());
                if (response.body().getState().equals("ok")) {
                    activity.finish();
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {

            }
        });

    }


}
